package com.hn.springframework.aop.aspect;

import com.hn.springframework.aop.intercept.HNMethodInterceptor;
import com.hn.springframework.aop.intercept.HNMethodInvocation;

import java.lang.reflect.Method;

public class HNAfterReturningAdviceInterceptor extends HNAbstractAspectAdvice implements HNAdvice, HNMethodInterceptor {

    private HNJoinPoint joinPoint;

    public HNAfterReturningAdviceInterceptor(Method aspectMethod, Object aspectTarget) {
        super(aspectMethod, aspectTarget);
    }


    @Override
    public Object invoke(HNMethodInvocation mi) throws Throwable {
        Object returnValue = mi.proceed();
        this.joinPoint = mi;
        afterReturning(returnValue, mi.getMethod(), mi.getArguments(), mi.getThis());
        return returnValue;
    }

    private void afterReturning(Object retVal, Method method, Object[] arguments, Object aThis) throws Throwable {
        super.invokeAdviceMethod(this.joinPoint, retVal,null);
    }
}
